package com.isolation.harassed.common.util;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

/**
 * 配置文件工具类，使用时请直接继承此类或使用类对象调用其中函数
 * 
 * @author allon
 * @version 1.0.2
 * @date 2015年3月11日
 */
public class Properties {

	private static SharedPreferences preferences;

	public final static void open(Context appContext) {
		if (preferences == null) {
			if (appContext == null) {
				throw new NullPointerException(
						"com.ihakul.connector.util.Properties context is null");
			} else {
				String props = appContext.getPackageName().replace(".", "_");
				preferences = appContext.getSharedPreferences(props,
						Context.MODE_PRIVATE);
			}
		}
	}

	public final void put(String key, long value) {
		Editor editor = preferences.edit();
		editor.putLong(key, value);
		editor.commit();
	}

	public final void put(String key, int value) {
		Editor editor = preferences.edit();
		editor.putInt(key, value);
		editor.commit();
	}

	public final void put(String key, boolean value) {
		Editor editor = preferences.edit();
		editor.putBoolean(key, value);
		editor.commit();
	}

	public final void put(String key, String value) {
		Editor editor = preferences.edit();
		editor.putString(key, value);
		editor.commit();
	}

	public final long getLong(String key, long defValue) {
		return preferences.getLong(key, defValue);
	}

	public final int getInt(String key, int defValue) {
		return preferences.getInt(key, defValue);
	}

	public final boolean getBoolean(String key, boolean defValue) {
		return preferences.getBoolean(key, defValue);
	}

	public final String getString(String key, String defValue) {
		return preferences.getString(key, defValue);
	}
}
